#pragma once

#include <linux/types.h>

#ifndef CONFIG_PAGE_SHIFT
#define CONFIG_PAGE_SHIFT 12
#endif

#define PAGE_SHIFT CONFIG_PAGE_SHIFT
#define PAGE_SIZE (1 << CONFIG_PAGE_SHIFT)

/*
 * Use struct definitions to apply C type checking
 */

/* Page Global Directory entry */
typedef struct
{
    unsigned long pgd;
} pgd_t;

/* Page Table entry */
typedef struct
{
    unsigned long pte;
} pte_t;

/* Page Middle Directory entry */
typedef struct
{
    unsigned long pmd;
} pmd_t;

/* Page 4th Directory entry */
typedef struct
{
    unsigned long p4d;
} p4d_t;

/* Page Upper Directory entry */
typedef struct
{
    unsigned long pud;
} pud_t;

typedef unsigned long pgprot_t;

typedef struct page *pgtable_t;


#define pte_val(x)	((x).pte)
#define pgd_val(x)	((x).pgd)
#define pgprot_val(x)	((x))

#define __pgprot(x)	(x)

#define __pgd(x)	((pgd_t) { (x) })
#define __pte(x)	((pte_t) { (x) })

uintptr_t __virt_to_phys(uintptr_t x);
uintptr_t linear_mapping_pa_to_va(uintptr_t x);

#define __pa(x) __virt_to_phys(x)

static inline phys_addr_t phys_to_virt(phys_addr_t pa)
{
    return linear_mapping_pa_to_va(pa);
}
